define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({

                showHeader: true,
                extend: {
                    index_url: 'form/field/index',
                    add_url: 'form/field/add',
                    edit_url: 'form/field/edit',
                    del_url: 'form/field/del',
                    multi_url: 'form/field/multi',
                    table: 'form_field',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'form_name', title: __('Form Name')},

                        {field: 'form_name', title: __('Form Name'), formatter: Table.api.formatter.form_name, searchList: {'normal': __('Normal'), 'hidden': __('Hidden')}, style: 'min-width:100px;'},

                        {field: 'title', title: __('Field Title')},
                        {field: 'name', title: __('Field Name')},
                        {field: 'type', title: __('Field Type')},
                        {field: 'show_type', title: __('Field Show Type')},


                        {field: 'length', title: __('Field Length')},
                        {field: 'decimal', title: __('Field Decimal')},
                        {field: 'required', title: __('Field Required')},
                        {field: 'notes', title: __('Field Notes')},
                        {field: 'default', title: __('Field Default')},
                        {field: 'backend_show', title: __('Backend Display')},
                        {field: 'setting', title: __('Field setting')},
                        {field: 'weigh', title: __('Weigh')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ],
                // search: false,  //是否启用查询
                // queryParams: function queryParams(params) {   //设置查询参数
                //     var param = {
                //         form_id: 2,
                //     };
                //     return param;
                // },
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});